package top.sdaily.web.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.sdaily.core.mybatis.Conditions;
import top.sdaily.core.utils.IdGeneratorUtils;
import top.sdaily.mapper.RoleMapper;
import top.sdaily.web.model.Role;
import top.sdaily.web.service.RoleService;

import java.util.List;

/**
 * Created by soya on 2016/10/29.
 */
@Service
@Transactional
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> getAll() {
        return roleMapper.findList(new Conditions(Role.class));
    }

    @Override
    public Role getRoleById(String id) {
        return roleMapper.findOne(new Conditions(Role.class).id(id));
    }

    @Override
    public int insertRole(Role role) {
        role.setPkid(IdGeneratorUtils.fresh());
        return roleMapper.insert(role);
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.update(role);
    }
}
